/*
 * ToolTip.java  0.4.0 / Oct 27, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing;

import com.cute4j.swing.graphics.Color;
import com.cute4j.swing.graphics.Font;

/**
 * ToolTip Class.
 *
 * @cute4j.native
 *    generate="header"
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public final class ToolTip extends Component {

// Private Static Fields. ------------------------------------------------------

  private static boolean toolTipsEnabled = true;

// Private Constructor. --------------------------------------------------------

 /**
  * Class has no instances.
  */
  private ToolTip() {
    // empty constructor body
  }

// Public Static Methods. ------------------------------------------------------

  /**
   * Returns <tt>true</tt> if the tooltips are enabled.
   *
   * @return <tt>true</tt> if the tooltips are enabled
   */
  public static boolean areToolTipsEnabled() {
    return toolTipsEnabled;
  }

  /**
   * Enables/disables tooltips.
   *
   * @param enabled <tt>true</tt> if enabled
   */
  public static void setToolTipsEnabled(boolean enabled) {
    if (toolTipsEnabled != enabled) {
      synchronized (Swing.CLASS_LOCK) {
        Swing.disposedCheck();
        _setEnabled(enabled);
        toolTipsEnabled = enabled;
      }
    }
  }

  /**
   * Shows tooltip at specified location.
   *
   * @param text the tooltip text
   * @param x the x-coordinate of the tooltip
   * @param y the y-coordinate of the tooltip
   */
  public static void showToolTip(String text, int x, int y) {
    showToolTip(text, x, y, null);
  }

  /**
   * Shows tooltip at specified location.
   *
   * @param text the tooltip text
   * @param x the x-coordinate of the tooltip
   * @param y int y-coordinate of the tooltip
   * @param component the component for which tooltip is provided
   */
  public static void showToolTip(String text, int x, int y,
                                 Component component) {
    if (text != null) {
      synchronized (Swing.CLASS_LOCK) {
        Swing.disposedCheck();
        if (component == null) {
          _showText(text, x, y, 0);
        } else {
          _showText(text, x, y, component._delegate);
        }
      }
    }
  }

  /**
   * Hides tooltip.
   */
  public static void hideToolTip() {
    synchronized (Swing.CLASS_LOCK) {
      Swing.disposedCheck();
      _hideText();
    }
  }

  /**
   * Sets background color for the tooltips.
   *
   * @param background the background color
   */
  public static void setToolTipsBackground(Color background) {
    synchronized (Swing.CLASS_LOCK) {
      Swing.disposedCheck();
      if (background == null) {
        _setNullBackground();
      } else {
        _setBackground(background.getARGB());
      }
    }
  }

  /**
   * Sets foreground color for the tooltips.
   *
   * @param foreground the foreground color
   */
  public static void setToolTipsForeground(Color foreground) {
    synchronized (Swing.CLASS_LOCK) {
      Swing.disposedCheck();
      if (foreground == null) {
        _setNullForeground();
      } else {
        _setForeground(foreground.getARGB());
      }
    }
  }

// Package-Private Native Methods. ---------------------------------------------

  static native void _setEnabled(boolean enabled);

  static native void _setFont(Font font);

  static native void _setBackground(int argb);

  static native void _setNullBackground();

  static native void _setForeground(int argb);

  static native void _setNullForeground();

  static native void _showText(String text, int x, int y,
                               long componentDelegate);

  static native void _hideText();

}
